﻿//-----------------------------------------------------------------------
// <copyright file="Retract.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the Retract class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Engine.Archive.EngineOperation
{
    using System.Diagnostics;
    using Tuples;

    /// <summary>
    /// Represents and 'retract' engine operation.   Retracts a single fact from the engine.
    /// </summary>
    internal class Retract : EngineOperation<object>
    {
        /// <summary>
        /// Initializes a new instance of the Retract class.
        /// </summary>
        /// <param name="session">The current tuple store session.</param>
        /// <param name="fact">A fact to be retracted.</param>
        public Retract(TupleStoreSession session, object fact)
        {
            Debug.Assert(fact != null, "Fact to be retracted cannot be null");

            this.session = session;
            this.data = fact;
        }

        #region IEngineOperation Members

        /// <summary>
        /// Performs the engine operation.
        /// </summary>
        /// <param name="facts">Ignored in this implementation.</param>
        /// <returns>Indicates if the engine should start a new match-resolve-do cycle.</returns>
        public override bool Perform(ref object[] facts)
        {
            // Retract the fact
            this.session.Retract(this.data);
            return false;
        }

        #endregion
    }
}
